<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Specification extends CI_Controller {
    /* function _construct()
      {
      parent::__construct();
      log_message('debug','Specification controller initialized');

      } */

    function Specification() {
        parent::__construct();
        $this->load->model('specification_model');
        $this->load->model('counter_model');
        $this->load->library('pagination');
        $this->template->set_theme('admin');
        $this->template->set_layout('admin_layout');
        $this->commoncall->check_admin_login();
    }

//--------Joy 14.09.2012---------//
    function index() {
        $per_page = 10;
        $offset = 0 + $this->uri->segment(4);
        $config['base_url'] = base_url() . 'admin/specification/index';
        $config['total_rows'] = $this->counter_model->specification_group_count('CAR');
        $config['uri_segment'] = '4';
        $config['full_tag_open'] = '';
        $config['full_tag_close'] = '';
        $this->pagination->initialize($config);
        $data['specification_group'] = $this->specification_model->get_specifications_groups('CAR', 'asc', $per_page, $offset);
        $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_specification_group', $data);
        
    }

//--------Joy 14.09.2012 For Specification management---------//
    function specification_group_insert() {
        if ($this->input->post('insert')) {
            $specification_group = $_POST['specification'];
            $this->form_validation->set_rules('specification', 'specification', 'required|xss_clean|is_unique[specification.specification]');
            $this->form_validation->set_rules('code', 'code', 'required|xss_clean');
            if ($this->form_validation->run()) {
                if ($specification_group != 'Enter Specification Group') {
                    $code = $this->input->post('code');
                    $this->specification_model->specification_group_insert('CAR', $specification_group, $code);
                }
                else
                    $this->session->set_flashdata('message', 'Type a Specification Group Name');
                redirect('admin/specification');
            } else {
                $this->session->set_flashdata('message', 'Specification Group already exists');
                redirect('admin/specification');
            }
        }
    }

//--------Joy 14.09.2012 For Specification management---------//
    function specification_group_update() {
        if ($this->input->post('update_specification_group')) {
            $specification_group = $_POST['specification'];
            $this->form_validation->set_rules('specification', 'specification', 'required|xss_clean|is_unique[specification.specification]');
            $this->form_validation->set_rules('code', 'code', 'required|xss_clean');
            $code = $this->input->post('code');
            if ($this->form_validation->run()) {
                $this->specification_model->specification_group_modify('CAR', $specification_group, $code);
            } else {
                $this->session->set_flashdata('message', 'Specification Group already exists');
                redirect('admin/specification');
            }
        }
        redirect('admin/specification');
    }

//--------Joy 14.09.2012 For Specification management---------//
    function specification_group_delete($code) {
        $this->specification_model->specification_group_delete('CAR', $code);
        redirect('admin/specification');
    }

//--------Joy 14.09.2012 For Specification management---------//
    function get_specification($code) {
        $per_page = 10;
        $offset = 0 + $this->uri->segment(5);
        $config['base_url'] = base_url() . 'admin/specification/get_specification/' . $code;
        $config['total_rows'] = $this->counter_model->specification_count('CAR', $code);
        $config['uri_segment'] = '5';
        $config['full_tag_open'] = '';
        $config['full_tag_close'] = '';
        $this->pagination->initialize($config);
        $data['code'] = $code;
        $data['specification_list'] = $this->specification_model->get_specifications('CAR', $code, 'asc', $per_page, $offset);
        $this->template->title('Dashboard', $this->settings_model->get_setting('webtitle'))
                ->set_partial('admin_header', 'header/admin_header')
                ->set_partial('admin_left_menu', 'sidebar/admin_left_menu')
                ->build('pages/admin_specification', $data);
    }

//--------Joy 14.09.2012 For Specification management---------//
    function specification_insert() {
        if ($this->input->post('insert')) {
            $specification_group = $_POST['specification'];
            $this->form_validation->set_rules('specification', 'specification', 'required|xss_clean|is_unique[specification.specification]');
            $this->form_validation->set_rules('code', 'code', 'required|xss_clean');
            $this->form_validation->set_rules('slno', 'slno', 'required|xss_clean');
            $code = $_POST['code'];
            $slno = $_POST['slno'];
            if ($this->form_validation->run()) {
                if ($feature_group != 'Enter Specification') {
                    $this->specification_model->specification_insert('CAR', $specification_group, $code, $slno);
                }
                else
                    $this->session->set_flashdata('message', 'Type a Specification Name');
                redirect('admin/specification/get_specification/' . trim($code));
            } else {
                $this->session->set_flashdata('message', 'Specification already exists');
                redirect('admin/specification/get_specification/' . trim($code));
            }
        }
    }

    //--------Joy 14.09.2012 For Specification management---------//
    function specification_update() {
        if ($this->input->post('update_specification')) {
            $feature_group = $_POST['specification'];
            $this->form_validation->set_rules('specification', 'specification', 'required|xss_clean|is_unique[specification.specification]');
            $this->form_validation->set_rules('specification_id', 'specification_id', 'required|xss_clean');
            $id = $this->input->post('specification_id');
            $code = $this->input->post('code');
            if ($this->form_validation->run()) {
                $this->specification_model->specification_modify('CAR', $feature_group, $id);
            } else {
                $this->session->set_flashdata('message', 'Specification already exists');
                redirect('admin/specification/get_specification/' . trim($code));
            }
        }
        redirect('admin/specification/get_specification/' . trim($code));
    }

    //--------Joy 14.09.2012 For Specification management---------//
    function specification_delete($code, $id) {

        $this->specification_model->specification_delete('CAR', $id);
        redirect('admin/specification/get_specification/' . trim($code));
    }

}

?>